package com.rulestech.salespro.unittest;

import java.io.IOException;
import java.util.Collection;

import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import com.rulestech.engine.DecisionEngine;
import com.rulestech.engine.EngineLogger;
import com.rulestech.engine.EngineResult;
import com.rulestech.framework.unittest.DataDrivenDecisionEngineBaseTest;
import com.rulestech.framework.unittest.TestCaseBuilder;
import com.rulestech.salespro.engine.SalesProEngine;
import com.rulestech.salespro.engine.SalesProEngineLogger;
import com.rulestech.salespro.engine.SalesProEngineResult;
import com.rulestech.salespro.inventory.Discount;

@RunWith(Parameterized.class)
public class SalesProEngineTest extends DataDrivenDecisionEngineBaseTest{

	/**
	 * User the data source to initiate the TestCaseBuilder and format the result from builder to the test cases.
	 * @return
	 * @throws IOException
	 */
	@Parameters
	public static Collection<Object[]>  getTestCases() throws IOException {
		TestCaseBuilder builder =  new SalesProTestCaseBuilder("/com/rulestech/salespro/unittest/SalesProTestData.xls");
		return format(builder.getTestCases());
	}
	
	@Override
	protected EngineResult buildDecisionEngineOutputReference() throws Exception {
		//try to calculate the actual output
		SalesProEngineResult actualOutput = new SalesProEngineResult();
		SalesProEngineResult output = (SalesProEngineResult)getOutput();
		Discount outputDiscount = (Discount)(output.getDiscount().clone());
		outputDiscount.setRate(0);
		actualOutput.setDiscount(outputDiscount);
		return actualOutput;
	}

	@Override
	protected DecisionEngine getDecisionEngine() {
		return new SalesProEngine ();
	}

	@Override
	protected EngineLogger getDecisionEngineLogger() {
		return new SalesProEngineLogger();
	}


	public SalesProEngineTest(Object input, Object output) throws Exception {
		super(input, output);
	}

}
